/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dao;

import pojo.Log;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 *
 * @author ahmed
 */
public class LogCrud
{
    private   Connection conn=null;
     private PreparedStatement stmt=null;

    public LogCrud()
    {

    	try {
    	     //rigister driver
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            //obtain connection
            conn =DriverManager.getConnection("jdbc:mysql://localhost:3306/dimensionproject","root","admin");

          } catch (Exception ex) {
           System.out.println(ex.getMessage());
        }
    }


     public boolean add(Log nextLog)
     {
         try {
             stmt = conn.prepareStatement("insert into log (a_id,date_time,status) values (?,?,?)");
             stmt.setInt(1,nextLog.getActivities().getAId());
             stmt.setString(2,nextLog.getDateTime());
             stmt.setString(3,nextLog.getStatus());
             stmt.execute();
            }
        catch (Exception e) {
            e.printStackTrace();
        }

    	return false;
     }



   public boolean update(Log nextLog ,int id)
   {
    	try {
             stmt = conn.prepareStatement("update log set a_id=?,date_time=?,status=? where l_id=? ");
              stmt.setInt(1,nextLog.getActivities().getAId());
             stmt.setString(2,nextLog.getDateTime());
             stmt.setString(3,nextLog.getStatus());
             stmt.setInt(4, id);

            return stmt.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    public boolean deleteById(int id)
   {

    	try {
             stmt = conn.prepareStatement("delete from log where l_id=?");
             stmt.setInt(1,id);
             return stmt.execute();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;

    }


}
